package com.mashibing;

import org.openjdk.jol.info.ClassLayout;

public class JustTest {
    public static void main(String[] args) {
        Object o = new Object();
    System.out.println(ClassLayout.parseInstance(o).toPrintable());
    test1(o);
    }

    /**
     * 测试线程中断是否会释放锁
     */
    public static void test1(Object o){

        Thread t1 = new Thread(() -> {
            synchronized (o) {
                System.out.println(1/0);
            }
        });
        Thread t2 = new Thread(() -> {
            synchronized (o) {
                try {
                    t1.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(2);
                System.out.println(ClassLayout.parseInstance(o).toPrintable());

            }
        });
        t1.start();
        t2.start();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
    }
}
